#pragma once
#include "ALBaseSaliency.h"

struct Region {
	Region() { pixNum = 0; }
	int pixNum;  // Number of pixels
	vector<pair<double, int> > freIdx;  // Frequency of each color and its index
	Point2d centroid;
};

class CALSRC : public CALBaseSaliency
{
public:
	CALSRC();
	CALSRC(CALStepItem* pStepItem);
	~CALSRC();

public:
	//https://github.com/abin24/Saliency-detection-toolbox

	virtual void test();
	virtual void convert();
	virtual void convert(const Mat &src, Mat &dst);

public:
	void calculateSaliencyMap(Mat *src, Mat * dst);
	int Quantize(const Mat& img3f, Mat &idx1i, Mat &_color3f, Mat &_colorNum, double ratio = 0.95);

	Mat GetRC(const Mat &img3f, double sigmaDist, double segK, int segMinSize, double segSigma);
private:
	void caRCulateSaliencyMap(Mat *src, Mat * dst);
	static const int SAL_TYPE_NUM = 5;

	void SmoothSaliency(const Mat &binColor3f, Mat &sal1d, float delta, const vector<vector<pair<double, int>>> &similar);
	void AbsAngle(const Mat& cmplx32FC2, Mat& mag32FC1, Mat& ang32FC1);
	void GetCmplx(const Mat& mag32F, const Mat& ang32F, Mat& cmplx32FC2);

	void BuildRegions(const Mat& regIdx1i, vector<Region> &regs, const Mat &colorIdx1i, int colorNum);
	void RegionContrast(const vector<Region> &regs, const Mat &color3fv, Mat& regSal1d, double sigmaDist);
};

